﻿//===================================GrayScaleAlgorithm.cs==============================\\
//===Bart Steijlen======\\


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace Team2_Vision
{
    class GrayScale : VisionAlgorithm
    {
        public GrayScale(String name) : base(name) { }
        public override System.Drawing.Bitmap DoAlgorithm(System.Drawing.Bitmap sourceImage, int matrix)
        {
            Bitmap returnImage = new Bitmap(sourceImage);
            colorChange(returnImage);
            return returnImage;
        }

        static Bitmap colorChange(Bitmap testImage)
        {
            Graphics g = Graphics.FromImage(testImage);
            ColorMatrix cm = new ColorMatrix(
                new float[][] 
                {
                    new float[] {.3f, .3f, .3f, 0, 0},
                    new float[] {.59f, .59f, .59f, 0, 0},
                    new float[] {.11f, .11f, .11f, 0, 0},
                    new float[] {0, 0, 0, 1, 0},
                    new float[] {0, 0, 0, 0, 1}
                });
            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(cm);
            g.DrawImage(testImage, new Rectangle(0, 0, testImage.Width, testImage.Height),
            0, 0, testImage.Width, testImage.Height, GraphicsUnit.Pixel, attributes);
            g.Dispose();
            return testImage;
        }
    }
}
